<h3> PhD Application Report </h3>
<p><?php echo $this->Html->link('PDF Version of report', array('action' => 'report',
																															 $this->data['Application']['id'],
																															 'pdf')); ?></p>
<h4> Personal Information</h4>
<table>
<tr><td>
<p>
	Applicant Name: <span class="response"><?php echo $this->data['Application']['firstname'] . ' '. $this->data['Application']['lastname']; ?></span><br />
	Email Address: <span class="response"><?php echo $this->data['User']['email']; ?></span><br />
	Primary Phone: <span class="response"><?php echo $this->data['Application']['phone_pri']; ?></span><br />
	Secondary Phone: <span class="response"><?php echo $this->data['Application']['phone_sec'];?></span><br />
</p>
</td>
<td>
	<dl><dt>References</dt>
		<dd>
		<?php 
			$num= count($this->data['Reference']);
			$count = 0;
			foreach ($this->data['Reference'] as $ref) {
				$count++;
				echo $ref['firstname'] . ' ' . $ref['lastname'] 
						. " (" . $this->Html->link('Form',array('controller' => 'References',
																										'action' => 'pdf',
																										$ref['id']));
				if (!empty($ref['file_name'])) {
					echo " | ". $this->Html->link('Letter', array('controller' => 'References',
																												'action' => 'viewLetter',
																												$ref['id']));
				}
				
				echo ')';
				if ($count < $num) {
					echo "<br/>";
				}
			}
		?>
		</dd>
	<dt>Attachments</dt>
		<dd>
			<?php 
				$num= count($this->data['Attachment']);
				$count = 0;
				foreach ($this->data['Attachment'] as $att) {
					$count++;
					echo $att['doc_type'] . ' -- ' . $this->Html->link( $att['file_name'], array('controller' => 'Attachments',
																																											 'action' => 'view',
																																											 $att['id']));
					if ($count < $num) {
						echo "<br/>";
					}
				}
			?>
		</dd>
	</dl>
</td>
</tr>
</table>
<div>
	<h4>Current Address</h4>
	<p>
		<?php $address = str_replace("\\n", "<br />", $this->data['Application']['address']);  
					$address = str_replace("\\r", "<br />", $address); 
					echo $address;			
		?>
	</p>	

<h4> Plans For Graduate Study </h4>	
<p> This application is a <span class="response"><?php echo $this->data['Studyinterest']['is_clinical_app']?'clinical':'non clinical';?> </span>application.
		<?php if ($this->data['Studyinterest']['is_clinical_app']) : ?> The applicant has indicated that they <span class="response">
		<?php echo $this->data['Studyinterest']['non_clinical_interest']?'would be':'would not be';?> </span>interested in being admitted for research training only.
		<?php endif; ?>
</p>

<table id="list">
<tr class="head"><th> &nbsp;</th><th>1st Choice</th><th>2nd Choice</th><th>3rd Choice</th><th>4th Choice</th></tr>
<tr class="odd"><th> Area:</th>
	<td><?php echo $this->data['Studyinterest']['area_1'] ?></td>
	<td><?php echo $this->data['Studyinterest']['area_2'] ?></td>
	<td><?php echo $this->data['Studyinterest']['area_3'] ?></td>
	<td><?php echo $this->data['Studyinterest']['area_4'] ?></td>
</tr>
<tr class="even"><th> Faculty:</th>
	<td><?php echo $this->data['Studyinterest']['faculty_1'] ?></td>
	<td><?php echo $this->data['Studyinterest']['faculty_2'] ?></td>
	<td><?php echo $this->data['Studyinterest']['faculty_3'] ?></td>
	<td><?php echo $this->data['Studyinterest']['faculty_4'] ?></td>
</tr>
<tr class="odd"><th> Research Interest:</th>
	<td><?php echo $this->data['Studyinterest']['res_area_1'] ?></td>
	<td><?php echo $this->data['Studyinterest']['res_area_2'] ?></td>
	<td><?php echo $this->data['Studyinterest']['res_area_3'] ?></td>
	<td><?php echo $this->data['Studyinterest']['res_area_4'] ?></td>
</tr>
</table>

<?php if (!empty($this->data['Studyinterest']['res_area_4'])) : ?>
<p> Other Research Interest Areas: 
<span class="response"> <?php echo $this->data['Studyinterest']['res_area_other']?> </span></p> 
<?php endif;?>

<dl> <dt>Career and Professional Goals:</dt>
	<dd><?php echo str_replace("\\n", "", $this->data['Studyinterest']['career_goals']); ?></dd>
</dl>

<dl> <dt>Also Applying To These Graduate Schools:</dt>
	<dd><?php echo str_replace("\\n", "", $this->data['Studyinterest']['grad_schools']); ?></dd>
</dl>

<dl>
<dt> The applicant <span class="response">
	<?php echo $this->data['Studyinterest']['applied_unpsych_fin']?'has':'has not';?>
	</span> applied for non-departmental financial support.
<?php if ($this->data['Studyinterest']['applied_unpsych_fin']) :?>
	 Specifically they have applied for the following support.</dt>
	<dd><?php echo str_replace("\\n", "", $this->data['Studyinterest']['unpsych_finances_info']);?></dd>
</dl>
<?php else : ?>
	</dt></dl>
<?php endif; ?>

<h4>Educational History</h4>

<table class="list">
<?php
	$th = array('School Name',
							'Start Date',
							'Finish Date',
							'Degrees earned',
							'Major/Minor program'
						 );
		echo $this->Html->tableHeaders($th,array('class'=> 'head'));
	
	foreach ($this->data['School'] as $output) {
		
		if (strpos($output['start_date'],'-')) {
			$tmp = explode('-', $output['start_date']);
			$output['start_date']= $tmp[1] . '/' . $tmp[0];
		}
		
		if (strpos($output['end_date'],'-')) {
			$tmp = explode('-', $output['end_date']);
			$output['end_date']= $tmp[1] . '/' . $tmp[0];
		}
		
		$tr = array($output['schoolname'],
								$output['start_date'],
								$output['end_date'],
								$output['degrees'],
								$output['major_minor']
							 );
		echo $this->Html->tableCells($tr, array('class' => 'odd'),array('class' => 'even')); 
	}
	unset ($output);
?>
</table>

<dl><dt>Cumulative GPA:</dt>
	<dd>
		Freshman: <?php echo $this->data['Courselist']['cgpa_fresh']?><br />
		Sophmore: <?php echo $this->data['Courselist']['cgpa_soph']?><br />
		Junior: <?php echo $this->data['Courselist']['cgpa_junior']?><br />
		Senior (so far): <?php echo $this->data['Courselist']['cgpa_senior']?><br />
		Overall CGPA: <?php echo $this->data['Courselist']['cgpa_all']?> <br />
		Graduate (if any): <?php echo $this->data['Courselist']['cgpa_grad']?>
	</dd>
</dl>

<?php 


if (isset($this->data['Courselist']['Course'])) {
	$output = null;
	foreach ($this->data['Courselist']['Course'] as $course) {
		$output[$course['category']][] = $course;
	}
	
	if(!is_array($output))
		$output = array();

	foreach ($output as $category => $courselist) {
		$count= 0;
		$sum= 0;
		foreach ($courselist as $course) {
			switch ($course['grade']) {
				case 'a': 
					$sum= $sum+4.0;
					$count++;
					break;
				case 'b':
					$sum= $sum+3.0;
					$count++;
					break;
				case 'c':
					$sum= $sum+2.0;
					$count++;
					break;
				case 'd':
					$sum= $sum+1.0;
					$count++;
					break;
				case 'f':
					$count++;
				default:
					break;
			}
		}			
		$this->data['Courselist'][$category] = ($count == 0)? 0: $sum / $count;
	}
	
	foreach ($output as $category => $courselist) {
	
		echo "<p>". ucwords($category) . " Courses:<br />Area GPA: ". number_format($this->data['Courselist'][$category], 2) ." </p>";
		
		echo '<table class="list">';
		
		$th = array('Course Name',
								'Grade',
								'Completed',
								'Date Completed'
							 );
		echo $this->Html->tableHeaders($th,array('class'=> 'head'));
		
		foreach ($courselist as $course) {
			
			if (strpos($course['complete_date'],'-')) {
				$tmp = explode('-', $course['complete_date']);
				$course['complete_date']= $tmp[1] . '/' . $tmp[0];
			}
			
			$tr = array($course['coursename'],
										strtoupper($course['grade']),
									$course['complete']?'Yes':'No',
									$course['complete_date']
								 );
			echo $this->Html->tableCells($tr, array('class' => 'odd'),array('class' => 'even')); 
		}
		echo '</table>';
	}
} 
?>
<h4> Scores </h4>

<dl><dt>GRE Scores (Percentiles)</dt>
	<dd>GRE Verbal: <?php echo $this->data['Score']['gre_verbal']?> (<?php echo $this->data['Score']['gre_verbal_p'] ?>%)<br />
			GRE Quantitative: <?php echo $this->data['Score']['gre_quant'] ?> (<?php echo $this->data['Score']['gre_quant_p'] ?>%)<br />
			GRE Analytical: <?php echo $this->data['Score']['gre_analytical'] ?> (<?php echo $this->data['Score']['gre_analytical_p'] ?>%)
	</dd>
</dl>

<?php if ($this->data['Application']['toefl_req']) : ?>
<dl><dt>TOEFL Scores</dt>
	<dd>TOEFL Score: <?php echo $this->data['Score']['toefl_score'] ?><br />
			TOEFL Version: <?php echo $this->data['Score']['toefl_version'] ?>
	</dd>
</dl>
<?php endif; ?>
